#!/usr/bin/env bash
index_no="01"
version="management"
containerName="rabbitmq-dev-${index_no}-${version}"
port="5672"
web_port="15672"
user="rb"
password="123456@#^^^"
install_dir="/docker/rabbitmq/"
#install_index_no_dir=$install_dir$index_no
#conf=$install_dir$index_no/conf/
#data=$install_dir$index_no/data/

echo '>>> Please later ... ...'

set -e
#sudo docker pull rabbitmq:$version |  grep "Image is up to date" || (echo Already up to date. Exiting... && exit 0)

echo '>>> Get old container id'
CID=$(sudo docker ps --all | grep ${containerName} | awk '{print $1}')
echo $CID
echo ">>> Stopping and deleting old container ${containerName}"
if [ "$CID" != "" ];
then
  sudo docker stop $CID
  sudo docker rm $CID
fi

#方式一：默认guest 用户，密码也是 guest
#docker run -d --hostname my-rabbit --name rabbit -p 15672:15672 -p 5672:5672 rabbitmq:management

#方式二：设置用户名和密码
#docker run -d --hostname my-rabbit --name rabbit -e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password -p 15672:15672 -p 5672:5672 rabbitmq:management

tempMountCommand="docker run -d --restart=always  -e RABBITMQ_DEFAULT_USER=${user} -e RABBITMQ_DEFAULT_PASS=${password}  -p ${port}:5672 -p ${web_port}:15672  --name ${containerName} rabbitmq:management"
echo ">>> 执行挂载的命令： ${tempMountCommand}"
# 挂载
$tempMountCommand